Added path distance options to xcsv
authorparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 17 Aug 2004 22:56:23 +0000 (22:56 +0000)
committerparkrrrr <parkrrrr@f51c46e8-681c-474f-0cfe-069cfd0219fb>
Tue, 17 Aug 2004 22:56:23 +0000 (22:56 +0000)
gpsbabel/csv_util.c
gpsbabel/internal_styles.c
gpsbabel/reference/dusky.gnuplot [new file with mode: 0644]
gpsbabel/reference/dusky.trk [new file with mode: 0755]
gpsbabel/reference/gnuplot.style [new file with mode: 0644]
gpsbabel/style/README.style
gpsbabel/style/tabsep.style
gpsbabel/testo

index 861b8f267156144ac898a8cf77b8439df14240a5..20899f080a5b445e7a0210a1be75cfc95b4c0004 100644 (file)
@@ -22,6 +22,7 @@
 #include <ctype.h>
 #include "defs.h"
 #include "csv_util.h"
+#include "grtcirc.h"
 
 #define MYNAME "CSV_UTIL"
 
 extern char *xcsv_urlbase;
 extern char *prefer_shortnames;
 
+static double pathdist = 0;
+static double oldlon = 999;
+static double oldlat = 999;
+    
 static int waypt_out_count;
 
 /*********************************************************************/
@@ -695,6 +700,12 @@ xcsv_parse_val(const char *s, waypoint *wpt, const field_map_t *fmp)
     } else
     if (strcmp(fmp->key, "GEOCACHE_CONTAINER") == 0) {
        wpt->gc_data.container = gs_mkcont(s);
+    } else
+    if ( strcmp( fmp->key, "PATH_DISTANCE_MILES") == 0) {
+       /* Ignored on input */
+    } else
+    if ( strcmp( fmp->key, "PATH_DISTANCE_KM") == 0 ) {
+       /* Ignored on input */
     } else {
        warning( MYNAME ": Unknown style directive: %s\n", fmp->key);
     }
@@ -776,6 +787,14 @@ xcsv_data_read(void)
     } while (!feof(xcsv_file.xcsvfp));
 }
 
+static void
+xcsv_resetpathlen()
+{
+    pathdist = 0;
+    oldlat = 999;
+    oldlon = 999;
+}
+
 /*****************************************************************************/
 /* xcsv_waypt_pr() - write output file, handling output conversions          */
 /*                  (the output meat)                                        */
@@ -791,6 +810,13 @@ xcsv_waypt_pr(const waypoint *wpt)
     int i;
     field_map_t *fmp;
     queue *elem, *tmp;
+    
+    if ( oldlon < 900 ) {
+       pathdist += tomiles(gcdist(oldlat*M_PI/180,oldlon*M_PI/180,
+                       wpt->latitude*M_PI/180,wpt->longitude*M_PI/180));
+    }
+    oldlon = wpt->longitude;
+    oldlat = wpt->latitude;
 
     if (strcmp(xcsv_file.field_delimiter, "\\w") == 0)
         write_delimiter = " ";
@@ -980,6 +1006,16 @@ xcsv_waypt_pr(const waypoint *wpt)
             sprintf(buff, fmp->printfc,
               wpt->altitude);
         } else
+               
+        /* DISTANCE CONVERSIONS**********************************************/
+       if (strcmp(fmp->key, "PATH_DISTANCE_MILES") == 0) {
+            /* path (route/track) distance in miles */
+            sprintf( buff, fmp->printfc, pathdist );
+       } else
+       if (strcmp(fmp->key, "PATH_DISTANCE_KM") == 0) {
+            /* path (route/track) distance in  */
+            sprintf( buff, fmp->printfc, pathdist * 5280*12*2.54/100/1000 );
+       } else
 
         /* TIME CONVERSIONS**************************************************/
         if (strcmp(fmp->key, "EXCEL_TIME") == 0) {
@@ -1063,8 +1099,8 @@ xcsv_data_write(void)
     }
 
     waypt_disp_all(xcsv_waypt_pr);
-    route_disp_all(xcsv_noop,xcsv_noop,xcsv_waypt_pr);
-    track_disp_all(xcsv_noop,xcsv_noop,xcsv_waypt_pr);
+    route_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr);
+    track_disp_all(xcsv_resetpathlen,xcsv_noop,xcsv_waypt_pr);
 
     /* output epilogue lines, if any. */
     QUEUE_FOR_EACH(&xcsv_file.epilogue, elem, tmp) {
index ab5bc6143c605210d962b985b035687054027cab..3b31cde74cc652d48745f9181c6c01b98b348337 100644 (file)
@@ -489,7 +489,8 @@ static char tabsep[] =
 "IFIELD  GEOCACHE_TERR,\"\",\"%3.1f\"\n"
 "IFIELD  GEOCACHE_CONTAINER,\"\",\"%s\"\n"
 "IFIELD  GEOCACHE_TYPE,\"\",\"%s\"\n"
-
+"IFIELD  PATH_DISTANCE_MILES,\"\",\"%f\"\n"
+"IFIELD  PATH_DISTANCE_KM, \"\", \"%f\"\n"
 ;
 static char xmap[] = 
 "# gpsbabel XCSV style file\n"
diff --git a/gpsbabel/reference/dusky.gnuplot b/gpsbabel/reference/dusky.gnuplot
new file mode 100644 (file)
index 0000000..f02feb7
--- /dev/null
@@ -0,0 +1,65 @@
+plot "-" with lines
+0.000000       623.352000
+2.971829       711.933600
+3.285049       715.214400
+3.616714       715.214400
+5.524296       705.372000
+9.412893       659.440800
+23.470340      606.948000
+25.016243      610.228800
+30.981982      623.352000
+32.467702      616.790400
+34.341455      629.913600
+39.151887      639.756000
+40.148722      643.036800
+43.855057      639.756000
+45.197995      639.756000
+50.241520      643.036800
+50.751146      613.509600
+52.418822      652.879200
+59.685934      662.721600
+61.251560      698.810400
+71.654560      738.180000
+72.528252      764.426400
+87.945745      721.776000
+88.792305      725.056800
+91.616705      764.426400
+99.657820      902.220000
+99.800297      905.500800
+99.971950      905.500800
+100.189154     902.220000
+100.572379     882.535200
+102.010350     882.535200
+102.804092     875.973600
+103.080392     872.692800
+107.397520     921.904800
+107.921923     915.343200
+111.807511     977.678400
+112.360714     974.397600
+113.798888     1003.924800
+115.624455     967.836000
+119.337749     1082.664000
+120.301609     1040.013600
+122.631756     1030.171200
+125.020430     1056.417600
+125.198791     1089.225600
+127.787125     1076.102400
+129.889131     997.363200
+130.326239     974.397600
+130.940014     971.116800
+131.414289     1020.328800
+142.699566     935.028000
+147.684227     905.500800
+154.362718     902.220000
+155.048874     889.096800
+155.659180     872.692800
+156.187932     846.446400
+156.833988     869.412000
+157.381754     875.973600
+159.890999     846.446400
+159.999868     856.288800
+163.196258     866.131200
+164.732014     869.412000
+164.932308     859.569600
+165.120360     849.727200
+e
diff --git a/gpsbabel/reference/dusky.trk b/gpsbabel/reference/dusky.trk
new file mode 100755 (executable)
index 0000000..26d099c
--- /dev/null
@@ -0,0 +1,63 @@
+$PMGNTRK,4122.991,N,08244.336,W,00190,M,030730.19,A,,170804*67\r
+$PMGNTRK,4120.566,N,08245.501,W,00217,M,031055.19,A,,170804*6B\r
+$PMGNTRK,4120.585,N,08245.862,W,00218,M,031137.19,A,,170804*64\r
+$PMGNTRK,4120.513,N,08246.233,W,00218,M,031200.20,A,,170804*6B\r
+$PMGNTRK,4120.853,N,08248.390,W,00215,M,031334.19,A,,170804*65\r
+$PMGNTRK,4121.287,N,08252.846,W,00201,M,031645.20,A,,170804*60\r
+$PMGNTRK,4124.603,N,08308.485,W,00185,M,032817.22,A,,170804*67\r
+$PMGNTRK,4125.265,N,08310.040,W,00186,M,032933.22,A,,170804*62\r
+$PMGNTRK,4127.211,N,08316.436,W,00190,M,033426.23,A,,170804*6E\r
+$PMGNTRK,4127.905,N,08317.885,W,00188,M,033539.23,A,,170804*63\r
+$PMGNTRK,4128.434,N,08319.936,W,00192,M,033711.23,A,,170804*67\r
+$PMGNTRK,4130.583,N,08324.711,W,00195,M,034107.24,A,,170804*60\r
+$PMGNTRK,4130.816,N,08325.823,W,00196,M,034156.24,A,,170804*69\r
+$PMGNTRK,4132.270,N,08329.653,W,00195,M,034458.24,A,,170804*6C\r
+$PMGNTRK,4132.495,N,08331.180,W,00195,M,034604.24,A,,170804*6A\r
+$PMGNTRK,4134.715,N,08336.218,W,00196,M,035012.25,A,,170804*60\r
+$PMGNTRK,4134.982,N,08336.689,W,00187,M,035037.26,A,,170804*68\r
+$PMGNTRK,4135.439,N,08338.524,W,00199,M,035159.25,A,,170804*6B\r
+$PMGNTRK,4135.725,N,08346.944,W,00202,M,035757.27,A,,170804*6D\r
+$PMGNTRK,4136.163,N,08348.663,W,00213,M,035914.28,A,,170804*68\r
+$PMGNTRK,4135.898,N,08400.725,W,00225,M,040751.28,A,,170804*66\r
+$PMGNTRK,4135.563,N,08401.634,W,00233,M,040834.28,A,,170804*64\r
+$PMGNTRK,4135.463,N,08419.515,W,00220,M,042119.30,A,,170804*63\r
+$PMGNTRK,4135.256,N,08420.457,W,00221,M,042200.30,A,,170804*64\r
+$PMGNTRK,4136.223,N,08423.467,W,00233,M,042419.30,A,,170804*68\r
+$PMGNTRK,4136.841,N,08432.759,W,00275,M,043059.32,A,,170804*69\r
+$PMGNTRK,4136.921,N,08432.885,W,00276,M,043110.32,A,,170804*6F\r
+$PMGNTRK,4136.784,N,08432.963,W,00276,M,043129.32,A,,170804*6D\r
+$PMGNTRK,4136.784,N,08433.215,W,00275,M,043213.32,A,,170804*6F\r
+$PMGNTRK,4137.115,N,08433.174,W,00269,M,043246.33,A,,170804*68\r
+$PMGNTRK,4138.362,N,08433.212,W,00269,M,043425.32,A,,170804*64\r
+$PMGNTRK,4138.607,N,08434.073,W,00267,M,043521.32,A,,170804*6B\r
+$PMGNTRK,4138.623,N,08434.393,W,00266,M,043541.33,A,,170804*66\r
+$PMGNTRK,4138.600,N,08439.404,W,00281,M,044011.33,A,,170804*6D\r
+$PMGNTRK,4138.462,N,08439.984,W,00279,M,044042.34,A,,170804*68\r
+$PMGNTRK,4138.239,N,08444.484,W,00298,M,044508.34,A,,170804*63\r
+$PMGNTRK,4138.120,N,08445.106,W,00297,M,044555.33,A,,170804*66\r
+$PMGNTRK,4138.074,N,08446.774,W,00306,M,044739.34,A,,170804*60\r
+$PMGNTRK,4137.843,N,08448.870,W,00295,M,044931.35,A,,170804*6A\r
+$PMGNTRK,4137.764,N,08453.178,W,00330,M,045258.34,A,,170804*61\r
+$PMGNTRK,4137.955,N,08454.267,W,00317,M,045357.35,A,,170804*6D\r
+$PMGNTRK,4137.894,N,08456.970,W,00314,M,045620.36,A,,170804*6B\r
+$PMGNTRK,4138.096,N,08459.729,W,00322,M,045913.35,A,,170804*6A\r
+$PMGNTRK,4138.095,N,08459.936,W,00332,M,045934.37,A,,170804*6F\r
+$PMGNTRK,4138.097,N,08502.940,W,00328,M,050333.36,A,,170804*60\r
+$PMGNTRK,4136.276,N,08502.817,W,00304,M,050534.38,A,,170804*61\r
+$PMGNTRK,4135.918,N,08502.984,W,00297,M,050557.38,A,,170804*64\r
+$PMGNTRK,4135.492,N,08503.411,W,00296,M,050629.37,A,,170804*6F\r
+$PMGNTRK,4135.093,N,08503.545,W,00311,M,050654.38,A,,170804*61\r
+$PMGNTRK,4125.307,N,08503.218,W,00285,M,051640.39,A,,170804*68\r
+$PMGNTRK,4121.266,N,08505.268,W,00276,M,052059.39,A,,170804*6A\r
+$PMGNTRK,4115.473,N,08505.236,W,00275,M,052641.40,A,,170804*66\r
+$PMGNTRK,4114.916,N,08505.515,W,00271,M,052716.41,A,,170804*69\r
+$PMGNTRK,4114.388,N,08505.566,W,00266,M,052747.41,A,,170804*62\r
+$PMGNTRK,4113.962,N,08505.792,W,00258,M,052814.41,A,,170804*66\r
+$PMGNTRK,4113.476,N,08506.163,W,00265,M,052847.41,A,,170804*6D\r
+$PMGNTRK,4113.012,N,08506.299,W,00267,M,052915.40,A,,170804*68\r
+$PMGNTRK,4110.836,N,08506.233,W,00258,M,053124.41,A,,170804*63\r
+$PMGNTRK,4110.746,N,08506.271,W,00261,M,053135.41,A,,170804*67\r
+$PMGNTRK,4110.661,N,08509.953,W,00264,M,053607.41,A,,170804*64\r
+$PMGNTRK,4109.329,N,08509.927,W,00265,M,053802.42,A,,170804*6F\r
+$PMGNTRK,4109.315,N,08509.697,W,00262,M,053828.41,A,,170804*68\r
+$PMGNTRK,4109.278,N,08509.486,W,00259,M,053858.41,A,,170804*6F\r
diff --git a/gpsbabel/reference/gnuplot.style b/gpsbabel/reference/gnuplot.style
new file mode 100644 (file)
index 0000000..980b91f
--- /dev/null
@@ -0,0 +1,26 @@
+# gpsbabel XCSV style file
+#
+# Format: GnuPlot output for track profiles
+# Author: Ron Parker
+#   Date: 17 Aug 2004
+#
+#
+
+DESCRIPTION            Gnuplot track profile
+
+# FILE LAYOUT DEFINITIIONS:
+#
+FIELD_DELIMITER                TAB
+RECORD_DELIMITER       NEWLINE
+BADCHARS               TAB     
+
+#
+# INDIVIDUAL DATA FIELDS:
+#
+PROLOGUE plot "-" with lines
+
+IFIELD  PATH_DISTANCE_MILES, "", "%lf"
+IFIELD  ALT_FEET, "", "%f"
+
+EPILOGUE e
+
index 78971a04c2f98beabcfefdfc020b817ea2bb74cd..e8bdb047ee32f8df6d4a0c1029c89100dd831aa0 100644 (file)
@@ -355,8 +355,20 @@ The fields used by the XCSV parser are as follows:
 
    example: GEOCACHE_TYPE,"","%s"
 
-
-
+ o PATH_DISTANCE_MILES
+   PATH_DISTANCE_MILES outputs the total length of the route or track from
+   the start point to the current point, in miles.  This and the altitude
+   could be used to create an elevation profile.  PATH_DISTANCE_MILES is
+   a DOUBLE PRECISION FLOAT.
+   PATH_DISTANCE_MILES is not valid as an input field.
+   PATH_DISTANCE_MILES is only meaningful if the data comes from a track
+   or a route; waypoint data will generate essentially meaningless output.
+
+   example: PATH_DISTANCE_MILES,"","%f"
+
+ o PATH_DISTANCE_KM
+   PATH_DISTANCE_KM is like PATH_DISTANCE_MILES except it outputs the 
+   length in kilometers.  
 
 EXAMPLES:
 --------
index 5967d07f4f1598f21b60ca79763b1b2d3094e64e..7176e813e2a343be25d39c18a5b89e7426ec74ac 100644 (file)
@@ -49,4 +49,5 @@ IFIELD  GEOCACHE_DIFF,"","%3.1f"
 IFIELD  GEOCACHE_TERR,"","%3.1f"
 IFIELD  GEOCACHE_CONTAINER,"","%s"
 IFIELD  GEOCACHE_TYPE,"","%s"
-
+IFIELD  PATH_DISTANCE_MILES,"","%f"
+IFIELD  PATH_DISTANCE_KM, "", "%f"
index ded25c418e9fda4e0a295832818679adf4819505..07a0eff1c03930b2b43a319fb5d3d893e3290d92 100755 (executable)
@@ -533,4 +533,12 @@ rm -f ${TMPDIR}/humanwrite.out
 ${PNAME} -i xcsv,style=reference/humanread.style -f reference/human.in -o xcsv,style=reference/humanwrite.style -F ${TMPDIR}/humanwrite.out
 compare ${TMPDIR}/humanwrite.out reference/humanwrite.out
 
+#
+# XCSV "path distance" test
+#
+rm -f ${TMPDIR}/pathdist.out
+${PNAME} -i magellan -f reference/dusky.trk -o xcsv,style=reference/gnuplot.style -F ${TMPDIR}/pathdist.out
+compare ${TMPDIR}/pathdist.out reference/dusky.gnuplot
+
+
 exit 0